package unibz.thaison.iosa;

import java.util.ArrayList;
import java.util.List;

public class UserManager {
	private static UserManager singleton;
	
	private UserManager() {
		users.add(new User("1", "Juha Rikkila", "Working"));
		users.add(new User("2", "Thai Son Nguyen", "Home"));
		users.add(new User("3", "User A", "Home"));
		users.add(new User("4", "User B", "Holiday"));
	};
	
	static {
		singleton = new UserManager(); 
	}
	
	public static UserManager getInstance() {
		return singleton;
	}
	
	private ArrayList<User> users = new ArrayList<User>();
	
	public void addUser(User user) {
		users.add(user);
	}
	
	public User get(String id) {
		for (int i=0; i<users.size(); i++) {
			User u = users.get(i);
			if (u.getId().equals(id)) return u;
		}
		return null;
	}
	
	public void delete(String id) {
		for (int i=0; i<users.size(); i++) {
			User u = users.get(i);
			if (u.getId().equals(id)) {
				users.remove(i); break;
			}
		}	
	}
	
	public List<User> getAll() {
		List<User> lst = new ArrayList<User>();
		lst.addAll(users);
		return lst;
	}
	
	public int count() {
		return users.size();
	}
}
